import request from '@/utils/request';

/**
 * 分页查询拖车运单
 */
export async function pageContainerBills(params) {
  const res = await request.get('/order/containerBill/page', { params });
  if (res.data.code === 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 查询拖车运单列表
 */
export async function listContainerBills(params) {
  const res = await request.get('/order/containerBill', {
    params
  });
  if (res.data.code === 0 && res.data.data) {
    return res.data.data;
  } 
  return Promise.reject(new Error(res.data.message));
}

/**
 * 根据id查询拖车运单
 */
export async function getContainerBill(id) {
  const res = await request.get('/order/containerBill/' + id);
  if (res.data.code === 0 && res.data.data) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 添加拖车运单
 */
export async function addContainerBill(data) {
  const res = await request.post('/order/containerBill', data);
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 修改拖车运单
 */
export async function updateContainerBill(data) {
  const res = await request.put('/order/containerBill', data);
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 修改拖车运单状态
 */
export async function updataState(data) {
  const res = await request.put('/order/containerBill/updataState', data);
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 删除拖车运单
 */
export async function removeContainerBill(id) {
  const res = await request.delete('/order/containerBill/' + id);
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 接单
 */
export async function platReceive(data) {
  const res = await request.put('/order/containerBill/platReceive', data);
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 现金单
 */
export async function cash(data) {
  const res = await request.put('/order/containerBill/cash', data);
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 落箱
 */
export async function dropBox(data) {
  const res = await request.put('/order/containerBill/dropBox', data);
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 预提
 */
export async function withholding(data) {
  const res = await request.put('/order/containerBill/withholding', data);
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 指派车队
 */
export async function carTeam(data) {
  const res = await request.put('/order/containerBill/carTeam', data);
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 上传箱号封号预录入
 */
export async function substitutePhoto(data) {
  const res = await request.put('/order/containerBill/substitutePhoto', data);
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 提箱
 */
export async function upBox(data) {
  const res = await request.put('/order/containerBill/upBox', data);
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 发起费用清单
 */
export async function costBill(data) {
  const res = await request.put('/order/containerBill/costBill', data);
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 修改状态
 */
export async function updateState(data) {
  const res = await request.put('/order/containerBill/updateState', data);
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 修改状态
 */
export async function finishState(data) {
  const res = await request.put('/order/containerBill/finishState', data);
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 应付费用审核
 */
export async function payableVerify(data) {
  const res = await request.put('/order/containerBill/payableVerify', data);
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 应收费用审核
 */
export async function receivableVerify(data) {
  const res = await request.put('/order/containerBill/receivableVerify', data);
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}


/**
 * 根据id查询拖车海运报关 关联表
 */
export async function getContainerOceanApply(params) {
  const res = await request.get('/order/containerBill/getContainerOceanApply', {params});
  if (res.data.code === 0 && res.data.data) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 添加拖车海运报关 关联表
 */
export async function saveContainerOceanApply(data) {
  const res = await request.post('/order/containerBill/saveContainerOceanApply', data);
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 删除拖车海运报关关联表
 */
export async function removeContainerOceanApply(data) {
  const res = await request.post('/order/containerBill/removeContainerOceanApply', data);
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

